<?php
namespace Home\Controller;
use Org\Com;
use Org\Com\Message;
use Think\Controller;
class SystemController extends Controller
{
    private $common=array("lxwmadd");
    
    /**
     * 检测权限
     */
    private function checkright($isajax=false){  
        $power=CONTROLLER_NAME."-".ACTION_NAME;
        $info=$_SESSION['my_info'];
        $bigcategroy=$info["bigcate"];
        $smallcategroy=explode(",", $info["smallcate"]);
        if(in_array(ACTION_NAME,$this->common)){
            if(!in_array($power, $smallcategroy)){
                if($isajax){
                   Message::Outofmessagenodata(99, "您没有权限"); 
                }else{
                   $this->error("没有权限");
                   exit();
                }
            }
        }
    }
    /**
     * 系统设置
     */
    public function lxwm(){
            $lx = M('lx');
            $res = $lx->find(1);
            if($res){
                $this->assign('res',$res);
            }
            $this->display();
    }
    
    /**
     * 系统设置或者修改
     */
    public function lxwmadd(){
        $this->checkright();
        $lx = M('lx');
        if(IS_POST){
            $key=I("post.key");
            $qq= I('post.qq');
            $tel = I('post.tel');
            $email = I('post.email');
            $data['qq'] = $qq;
            $data['phone'] = $tel;
            $data['email'] = $email;
            if(!$lx->find(1)){
                if($lx->data($data)->add()){
                    $this->success('添加成功');
                }else{
                    $this->error('添加失败');
                }
            }else{
                if(isset($key)){
                    if($lx->where(array("id"=>intval($key)))->data($data)->save()){
                        $this->success('修改成功');
                    }else{
                        $this->error('修改失败');
                    }
                }else{
                    $this->error('参数错误');
                }
            }
        }
    }
}

?>